package org.javabasics.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLDecoder;

/**
 * Created by LUOLIANG on 2016/9/21.+
 * 使用字节输出流创建文件
 */
public class FileOutputStreamTest {
    public static void main(String[] args) {
        String path = URLDecoder.decode(
                System.getProperty("user.dir") + "/basicsPractice/src/org/javabasics/io/");
        try (
                FileInputStream fis = new FileInputStream(path + "FileOutputStreamTest.java");
                FileOutputStream fos = new FileOutputStream(path + "newFile.txt")
        ) {
            byte[] bbuf = new byte[32];
            int hasRead = 0;
            while ((hasRead = fis.read(bbuf)) > 0) {
                fos.write(bbuf, 0, hasRead);
            }
            System.out.println("文件写入完成");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
